package com.biomatch.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.biomatch.domain.DancePosition;
import com.biomatch.domain.Type;
import com.biomatch.dto.Pagination;
import com.biomatch.response.RestResponse;
import com.biomatch.response.RestResult;
import com.biomatch.service.DanceTypeService;
import com.biomatch.utils.Internationalize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("dance.dancerType")
@RequestMapping("/dancertype")
@Api(value = "舞种管理")
public class DanceTypeController {

    @Autowired
    private DanceTypeService danceTypeService;

    @Autowired
    private Internationalize internationalize;


    @RequestMapping(value="/getAllTypeByPage", method = RequestMethod.POST)
    @ApiOperation(value = "分页获取位置", response = Type.class, httpMethod = "POST")
    public RestResult<Type> getAllTypeByPage(@RequestBody Pagination pagination) {
        IPage<Type> result=danceTypeService.getAllTypeByPage(pagination);
        return RestResponse.success(result);
    }

    @RequestMapping(value="/getAll", method = RequestMethod.POST)
    @ApiOperation(value = "获取全部舞种", response = Type.class, httpMethod = "POST")
    public RestResult<List<Type>> getAll() {
        List<Type> result =danceTypeService.getAll();
        return RestResponse.success(result);
    }

    @RequestMapping(value="/saveOrUpdate", method = RequestMethod.POST)
    @ApiOperation(value = "新增或更新舞种", response = Type.class, httpMethod = "POST")
    public RestResult<Type> saveOrUpdate(@RequestBody Type type) {
        Type result = danceTypeService.saveOrUpdate(type);
        if (result == null) {
            return RestResponse.error(internationalize.getMessage("position.name.repeat"));
        } else {
            return RestResponse.success(result);
        }
    }

    @RequestMapping(value="/delete", method = RequestMethod.POST)
    @ApiOperation(value = "删除舞种", response = Type.class, httpMethod = "POST")
    public RestResult<Type> delete(@RequestBody Type type ) {
        Type result = danceTypeService.delete(type);
        if (result == null) {
            return RestResponse.error(internationalize.getMessage("position.status.used"));
        } else {
            return RestResponse.success(result);
        }
    }



}
